<template>
    <div style="width: 100%;">
        <div class="header" style="background-color: white">
            <el-page-header @back="goBack" content="综合统计中心">
            </el-page-header>
        </div>
        <el-divider></el-divider>
        <el-tabs v-model="activeName">
            <el-form>
                <el-container>
                    <el-form-item label="日期："></el-form-item>
                    <el-form-item>
                        <el-date-picker
                                v-model="params.starttime"
                                type="date"
                                 value-format="yyyy-MM-dd">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item style="margin-left: 20px">
                        <el-date-picker
                                v-model="params.endtime"
                                type="date"
                                value-format="yyyy-MM-dd">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item style="margin-left: 20px">
                        <el-button type="primary" @click="List()" icon="el-icon-search">检索</el-button>
                    </el-form-item>
                </el-container>
            </el-form>
            <el-divider></el-divider>
            <el-tab-pane label="业务收费汇总表" name="first">
                <h1 style="text-align:center;margin-bottom: 30px;margin-top: 50px">律所业务收费汇总表</h1>
                <el-table
                        :data="cwinoutCountData"
                        border show-summary
                        style="width: 100%;font-size: 18px;"
                >
                    <el-table-column
                            prop="m"
                            label="月份">
                    </el-table-column>
                    <el-table-column
                            prop="h"
                            label="合同金额"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="p"
                            label="开票金额">
                    </el-table-column>
                    <el-table-column
                            prop="s"
                            label="收款金额">
                    </el-table-column>
                </el-table>
            </el-tab-pane>

            <el-tab-pane label="个人业务总计汇总表" name="second">
                <h1 style="text-align:center;margin-bottom: 30px;margin-top: 50px">个人业务总计汇总表</h1>
                <el-table
                        :data="empCountData"
                        border show-summary
                        style="width: 100%;font-size: 18px;"
                >
                    <el-table-column
                            prop="n"
                            label="姓名">
                    </el-table-column>
                    <el-table-column
                            prop="k"
                            label="开票金额"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="s"
                            label="收款金额">
                    </el-table-column>
                </el-table>
            </el-tab-pane>
            <el-tab-pane label="出纳统计" name="third">
                <h1 style="text-align:center;margin-bottom: 30px;margin-top: 50px">律所业务收费汇总表</h1>
                <h3 style="text-align:center;margin-bottom: 10px;margin-top: 30px">网银出纳表</h3>
                <el-table
                        :data="wangyinData"
                        border show-summary
                        :summary-method="getSummaries"
                        style="width: 100%;font-size: 18px;"
                >
                    <el-table-column
                            prop="cw_inout_date"
                            label="日期">
                    </el-table-column>
                    <el-table-column
                            prop="cw_name"
                            label="类别"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="cw_remark"
                            label="摘要">
                    </el-table-column>
                    <el-table-column label="收入" prop="inMoney">
                    </el-table-column>
                    <el-table-column label="支出" prop="outMoney"></el-table-column>
                </el-table>
                <h3 style="text-align:center;margin-bottom: 10px;margin-top: 50px">支付宝出纳表</h3>
                <el-table
                        :data="zhifubaoData"
                        border show-summary
                        :summary-method="getSummaries"
                        style="width: 100%;font-size: 18px;"
                >
                    <el-table-column
                            prop="cw_inout_date"
                            label="日期">
                    </el-table-column>
                    <el-table-column
                            prop="cw_name"
                            label="类别"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="cw_remark"
                            label="摘要">
                    </el-table-column>
                    <el-table-column label="收入" prop="inMoney">
                    </el-table-column>
                    <el-table-column label="支出" prop="outMoney"></el-table-column>
                </el-table>
                <h3 style="text-align:center;margin-bottom: 10px;margin-top: 50px">微信出纳表</h3>
                <el-table
                        :data="weixinData"
                        border show-summary
                        :summary-method="getSummaries"
                        style="width: 100%;font-size: 18px;"
                >
                    <el-table-column
                            prop="cw_inout_date"
                            label="日期">
                    </el-table-column>
                    <el-table-column
                            prop="cw_name"
                            label="类别"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="cw_remark"
                            label="摘要">
                    </el-table-column>
                    <el-table-column label="收入" prop="inMoney">
                    </el-table-column>
                    <el-table-column label="支出" prop="outMoney"></el-table-column>
                </el-table>
                <h3 style="text-align:center;margin-bottom: 10px;margin-top: 50px">其他方式</h3>
                <el-table
                        :data="otherData"
                        border show-summary
                        :summary-method="getSummaries"
                        style="width: 100%;font-size: 18px;"
                >
                    <el-table-column
                            prop="cw_inout_date"
                            label="日期">
                    </el-table-column>
                    <el-table-column
                            prop="cw_name"
                            label="类别"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="cw_remark"
                            label="摘要">
                    </el-table-column>
                    <el-table-column label="收入" prop="inMoney">
                    </el-table-column>
                    <el-table-column label="支出" prop="outMoney"></el-table-column>
                </el-table>
            </el-tab-pane>
            <el-tab-pane label="分类开票汇总" name="fourth">
                <h1 style="text-align:center;margin-bottom: 30px;margin-top: 50px">分类开票统计</h1>
                <el-table
                        :data="TypeCountData"
                        border show-summary
                        style="width: 100%;font-size: 18px;"
                >
                    <el-table-column
                            prop="m"
                            label="月份">
                    </el-table-column>
                    <el-table-column
                            prop="m"
                            label="民事案件"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="xsaj"
                            label="刑事案件">
                    </el-table-column>
                    <el-table-column
                            prop="xzaj"
                            label="行政案件">
                    </el-table-column>
                    <el-table-column
                            prop="fssflsw"
                            label="非诉讼法律事务">
                    </el-table-column>
                    <el-table-column
                            prop="flgw"
                            label="法律顾问">
                    </el-table-column>
                    <el-table-column
                            prop="flyz"
                            label="法律援助">
                    </el-table-column>
                    <el-table-column
                            prop="zxaj"
                            label="执行案件">
                    </el-table-column>
                    <el-table-column
                            prop="zbaj"
                            label="中保案件">
                    </el-table-column>
                    <el-table-column
                            prop="zcaj"
                            label="仲裁案件">
                    </el-table-column>
                    <el-table-column
                            prop="pcaj"
                            label="破产案件"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="zxdxws"
                            label="咨询代写文书" >
                    </el-table-column>
                </el-table>

            </el-tab-pane>
            <el-tab-pane label="法律顾问统计" name="fifth">
                <h1 style="text-align:center;margin-bottom: 30px;margin-top: 50px">法律顾问统计</h1>
                <el-table
                        :data="guwenCountData"
                        border show-summary
                        style="width: 100%;font-size: 18px;"
                >
                    <el-table-column
                            prop="case_no"
                            label="案号">
                    </el-table-column>
                    <el-table-column
                            prop="case_wtr"
                            label="委托人"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="case_attorney"
                            label="承办律师">
                    </el-table-column>
                    <el-table-column
                            prop="case_cause"
                            label="委托案由">
                    </el-table-column>
                    <el-table-column
                            prop="case_agencyfee"
                            label="顾问费">
                    </el-table-column>
                    <el-table-column
                            prop="collection_time"
                            label="起始日期"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="case_approval_endtime"
                            label="截止日期" >
                    </el-table-column>
                </el-table>

            </el-tab-pane>
        </el-tabs>
    </div>
</template>

<script>
    import  CwInoutService from '../../../model/ww/cw_inout/CwInoutService'
    import  CaseLawService from '../../../model/gs/CaseLawService'
    const cwInoutService=CwInoutService.getInstance();
    const caseLawService=CaseLawService.getInstance();
    export default {
        name: "ActionMagess",
        data() {
            return {
                activeName: 'first',
                params:{},//业务收费时间
                cwinoutCountData:[],//业务收费数据
                empCountData:[],//个人汇总数据
                wangyinData:[],//网银数据
                yinhangkaData:[],//银行卡数据
                zhifubaoData:[],//支付宝数据
                weixinData:[],//微信数据
                otherData:[],//其他数据
                guwenCountData:[], //顾问统计数据
                TypeCountData:[], //开票总汇数据
            };
        },
        methods: {
            List(){
                switch (this.activeName){
                    case 'first': this.List1();break;
                    case 'second': this.List2();break;
                    case 'third': this.List3();break;
                    case 'fourth': this.List4();break;
                    case 'fifth': this.List5();break;
                }
            },

            List1(){
                cwInoutService.countList(this.params).then((response)=>{
                    this.cwinoutCountData=response.data.data
                })
            },

            List2(){
                cwInoutService.empCountList(this.params).then((response)=>{
                    this.empCountData=response.data.data
                })
            },
            List3(){
                const params1 = {payType:1}
                const params2 = {payType:2}
                const params3 = {payType:3}
                const params4= {payType:4}
                const params5 = {payType:5}
                Object.keys(this.params).forEach(key => {
                    params1[key] = this.params[key]
                    params2[key] = this.params[key]
                    params3[key] = this.params[key]
                    params4[key] = this.params[key]
                    params5[key] = this.params[key]
                })
                this.$axios.all([cwInoutService.payType(params1),
                                cwInoutService.payType(params2),
                                cwInoutService.payType(params3),
                                cwInoutService.payType(params4),
                                cwInoutService.payType(params5)])
                .then(this.$axios.spread((response1,response2,response3,response4,response5)=>{
                    this.wangyinData=response1.data.data
                    this.wangyinData.forEach(item => {
                        if(item.type == '+'){
                            item.inMoney = item.cw_inout_money
                            item.outMoney = 0
                        }else{
                            item.inMoney = 0
                            item.outMoney = item.cw_inout_money
                        }
                    })

                    this.yinhangkaData=response2.data.data
                    this.yinhangkaData.forEach(item => {
                        if(item.type == '+'){
                            item.inMoney = item.cw_inout_money
                            item.outMoney = 0
                        }else{
                            item.inMoney = 0
                            item.outMoney = item.cw_inout_money
                        }
                    })
                    this.zhifubaoData=response3.data.data
                    this.zhifubaoData.forEach(item => {
                        if(item.type == '+'){
                            item.inMoney = item.cw_inout_money
                            item.outMoney = 0
                        }else{
                            item.inMoney = 0
                            item.outMoney = item.cw_inout_money
                        }
                    })
                    this.weixinData=response4.data.data
                    this.weixinData.forEach(item => {
                        if(item.type == '+'){
                            item.inMoney = item.cw_inout_money
                            item.outMoney = 0
                        }else{
                            item.inMoney = 0
                            item.outMoney = item.cw_inout_money
                        }
                    })
                    this.otherData=response5.data.data
                    this.otherData.forEach(item => {
                        if(item.type == '+'){
                            item.inMoney = item.cw_inout_money
                            item.outMoney = 0
                        }else{
                            item.inMoney = 0
                            item.outMoney = item.cw_inout_money
                        }
                    })

                }))
            },
            List4(){
                caseLawService.kpCount(this.params).then((response)=>{
                    this.TypeCountData=response.data.data
                })
            },
            List5(){
                caseLawService.dlfCount(this.params).then((response)=>{
                    this.guwenCountData=response.data.data
                })
            },
            // formatDateTime(inputTime, mode) {  //格式转换表格中的领用日期
            //     var date = new Date(inputTime.createtime);
            //     var y = date.getFullYear();
            //     var m = date.getMonth() + 1;
            //     m = m < 10 ? ('0' + m) : m;
            //     var d = date.getDate();
            //     d = d < 10 ? ('0' + d) : d;
            //     var h = date.getHours();
            //     h = h < 10 ? ('0' + h) : h;
            //     var minute = date.getMinutes();
            //     var second = date.getSeconds();
            //     minute = minute < 10 ? ('0' + minute) : minute;
            //     second = second < 10 ? ('0' + second) : second;
            //     return mode == undefined ? y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second : y + '-' + m + '-' + d + ' ' + h + ':' + minute;
            //
            // }
            // ,
            getSummaries(param) {
                const { columns, data } = param;
                const sums = [];
                columns.forEach((column, index) => {
                    if (index === 0) {
                        sums[index] = '总计';
                        return;
                    }
                    const values = data.map(item => Number(item[column.property]));
                    if (!values.every(value => isNaN(value))) {
                        sums[index] = values.reduce((prev, curr) => {
                            const value = Number(curr);
                            if (!isNaN(value)) {
                                return prev + curr;
                            } else {
                                return prev;
                            }
                        }, 0);
                        sums[index] += ' 元';
                    } else {
                        sums[index] = '';
                    }
                });

                return sums;
            },
            goBack(){
                history.back()
            }
        },
        created() {
            this.List()
        }
    }
</script>

<style scoped>

</style>
